unit JATUIF_Component_SnakeBox;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Video, JATUIF_Component, JATUIF_Driver_Screen;

Type

    { TSnakeBox }

    TSnakeBox = class(TComponent)
      Protected
        Procedure _OnKeyPress(Key:Char); override;
        Procedure _OnMouseEnter; override;
        Procedure _OnMouseLeave; override;
        Procedure _OnClick; override;
        Procedure _OnLoseFocus; override;
        Procedure Draw; override;
      Private
        { Private Properties & Methods }
        Back       : Byte;
        SX,SY      : Byte;
        OSX,OSY    : Byte;
        SnakeCol   : Byte;
      Public
        Constructor Create(Parent:TScreen; X1,Y1,X2,Y2:Integer; Background : Byte; SnakeColor : Byte);
        Procedure Move;
    end;

implementation

{ TSnakeBox }

constructor TSnakeBox.Create(Parent: TScreen; X1, Y1, X2, Y2: Integer; Background : Byte; SnakeColor : Byte);
begin
     SnakeCol:= SnakeColor;
     SX:= Self.GetX1;
     SY:= Self.GetY1;
     Back:= Background;
     inherited Create(Parent, X1, Y1, X2, Y2);
end;

procedure TSnakeBox.Move;
begin
     OSX:= SX;
     OSY:= SY;
     Inc(SX);
     If SX > Self.GetX2 then begin
        Inc(SY);
        SX:= Self.GetX1;
     end;
     If SY > Self.GetY2 then begin
        SY:= Self.GetY1;
     end;
     Draw;
end;

procedure TSnakeBox.Draw;
Var
   i,n:integer;

begin
     Screen.DrawXY(Self.GetTag,OSX,OSY,'    ', Back, Back);
     Screen.DrawXY(Self.GetTag,SX,SY,#7+#7+#7+#7, SnakeCol, Back);
end;

{ Callback Events }

procedure TSnakeBox._OnKeyPress(Key: Char);
begin
     inherited _OnKeyPress(Key);
end;

procedure TSnakeBox._OnMouseEnter;
begin
     inherited _OnMouseEnter;
end;

procedure TSnakeBox._OnMouseLeave;
begin
     inherited _OnMouseLeave;
end;

procedure TSnakeBox._OnClick;
begin
     inherited _OnClick;
end;

procedure TSnakeBox._OnLoseFocus;
begin
     inherited _OnLoseFocus;
end;

end.

